import type { IExamRecord } from '@shared/types/exam';

import { httpRequest } from '../httpRequest';
import type {
  IResponse,
  IResWithPage,
} from '../types';

export interface GetExamRecordListParams {
  page?: number
  limit?: number
  exam_id?: string
  status?: string
  username?: string
  start_date?: string
  end_date?: string
}

export interface BatchDeleteExamRecordsRequest {
  ids: string[]
}

export const examRecordApi = {
  // 获取考试记录列表
  getExamRecordList(params: GetExamRecordListParams): Promise<IResWithPage<IExamRecord & {
    user_id: {
      _id: string
      username: string
      phone: string
    }
    exam_id: {
      _id: string
      exam_name: string
    }
  }>> {
    return httpRequest.get('/api/v1/exam-record/list', { params })
  },

  // 获取考试记录详情
  getExamRecordDetail(id: string): Promise<IResponse<IExamRecord & {
    user_id: {
      _id: string
      username: string
      phone: string
    }
    exam_id: {
      _id: string
      exam_name: string
    }
  }>> {
    return httpRequest.get(`/api/v1/exam-record/${id}`)
  },

  // 删除考试记录
  deleteExamRecord(id: string): Promise<IResponse<null>> {
    return httpRequest.delete(`/api/v1/exam-record/${id}`)
  },

  // 批量删除考试记录
  batchDeleteExamRecords(ids: string[]): Promise<IResponse<null>> {
    return httpRequest.post('/api/v1/exam-record/batch-delete', { ids })
  },

  // 导出考试记录
  exportExamRecords(params: GetExamRecordListParams): Promise<Blob> {
    return httpRequest.get('/api/v1/exam-record/export', {
      params,
      responseType: 'blob'
    })
  }
}
